using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ICP_MS;

public class GenerateJson
{
	public static string ConnectHost()
	{
		JObject obj = new JObject();
		obj["CMD"] = 1;
		obj["Ver"] = "1.0";
		obj["Des"] = "Status";
		obj["Status"] = "iMass";
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	public static string GetStatus(int status)
	{
		JObject obj = new JObject();
		obj["CMD"] = 2;
		obj["Ver"] = "1.0";
		obj["Des"] = "Status";
		obj["Status"] = status;
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	public static string PlasmaOn(int status)
	{
		JObject obj = new JObject();
		obj["CMD"] = 3;
		obj["Ver"] = "1.0";
		obj["Des"] = "Turn Plasma On";
		obj["PlasmaStaus"] = status;
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	public static string PlasmaOff(int status)
	{
		JObject obj = new JObject();
		obj["CMD"] = 10;
		obj["Ver"] = "1.0";
		obj["Des"] = "Turn Plasma Off";
		obj["PlasmaStaus"] = status;
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	public static string SetParam(bool tt)
	{
		JObject obj = new JObject();
		obj["CMD"] = 4;
		obj["Ver"] = "1";
		if (tt)
		{
			obj["Des"] = "Set Method Success";
		}
		else
		{
			obj["Des"] = "Set Method Fail";
		}
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	public static string ReturnData(int haveError, int errors, int sweepindex, int runindex, int channels, List<double> results)
	{
		JObject obj = new JObject();
		obj["CMD"] = 6;
		obj["Ver"] = "1.0";
		obj["Des"] = "Data";
		obj["HaveError"] = haveError;
		obj["Errors"] = errors;
		obj["SweepIndex"] = sweepindex;
		obj["RunIndex"] = runindex;
		obj["Channels"] = channels;
		obj["Results"] = new JArray(results);
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	public static string SampleIn()
	{
		JObject obj = new JObject();
		obj["CMD"] = 9;
		obj["Ver"] = "1.0";
		obj["Des"] = "Sample in";
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	public static string CheckFinished(int result, string msg = "")
	{
		JObject obj = new JObject();
		obj["CMD"] = 8;
		obj["Ver"] = "1.0";
		obj["Des"] = "AutoTune";
		obj["Result"] = result;
		obj["Message"] = msg;
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	public static string JumpHeart()
	{
		JObject obj = new JObject();
		obj["CMD"] = 99;
		obj["Ver"] = "1.0";
		obj["Des"] = "Heart Jump";
		string jsonText = obj.ToString();
		return AddBrackets(jsonText);
	}

	private static void ParseJson(string json)
	{
		JObject obj = (JObject)JsonConvert.DeserializeObject(json);
	}

	public static string AddBrackets(string json)
	{
		return "[" + json + "]";
	}
}
